package cn.jackyu.stock.stock_grid_trading.event.producer;

import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.web.reactive.function.client.WebClient;

@Service
@Slf4j
public class StockService {

    private final SseClientUtil sseClientUtil;

    public StockService() {
        this.sseClientUtil = new SseClientUtil(WebClient.builder(), "");
    }

    public void startSubscription() {
        // 订阅股票代码1
        sseClientUtil.subscribe("1.512690", message -> {
            System.out.println("Received message for 100.KLSE: " + message);
        });

    }

    public void stopSubscription(String code) {
        sseClientUtil.unsubscribe(code);
    }

    public void printSubscribedCodes() {
        Iterable<String> codes = sseClientUtil.getSubscribedCodes();
        System.out.println("Subscribed codes: " + codes);
    }

    public void stopAllSubscriptions() {
        sseClientUtil.unsubscribeAll();
    }
}